from app import db
from datetime import datetime

class BodyComposition(db.Model):
    __tablename__ = 'body_composition'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    record_date = db.Column(db.DateTime, default=datetime.utcnow)
    
    weight = db.Column(db.Float)
    bmi = db.Column(db.Float)
    body_fat_percentage = db.Column(db.Float)
    muscle_mass = db.Column(db.Float)
    water_percentage = db.Column(db.Float)
    waist_circumference = db.Column(db.Float)
    hip_circumference = db.Column(db.Float)
    
    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'record_date': self.record_date.isoformat(),
            'weight': self.weight,
            'bmi': self.bmi,
            'body_fat_percentage': self.body_fat_percentage,
            'muscle_mass': self.muscle_mass,
            'water_percentage': self.water_percentage,
            'waist_circumference': self.waist_circumference,
            'hip_circumference': self.hip_circumference
        }